package com.css.zfzx.sjcj.common.utils;

import com.css.bpm.platform.api.local.PlatformAPI;
import com.css.bpm.platform.org.dept.repository.entity.DeptEntity;
import com.css.bpm.platform.org.division.repository.entity.DivisionEntity;
import com.css.bpm.platform.org.role.repository.entity.RoleEntity;
import com.css.bpm.platform.utils.PlatformSessionUtils;

import java.util.List;

public class ServerUtil {

    /**
     * 判断某用户是否存在角色
     *
     * @param roleEntities
     * @param code
     * @return
     */
    public static boolean isContaintRole(List<RoleEntity> roleEntities, String code) {
        boolean flag = false;
        for (RoleEntity role : roleEntities) {
            if (code.equals(role.getRoleCode())) {
                flag = true;
                break;
            }
        }
        if (flag) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * 获取当前用户的地区
     *
     * @return
     */
    public static DivisionEntity getDivisionEntity() {
        String userId = PlatformSessionUtils.getUserId();
        DeptEntity mainDept = PlatformAPI.getOrgAPI().getUserAPI().getMainDept(userId);
        String divisionId = mainDept.getDivisionId();
        DivisionEntity divisionById = PlatformAPI.getDivisionAPI().getDivisionById(divisionId);
        return divisionById;
    }
}
